#include <iostream>
#include <memory>

class Fruit
{
public:
    Fruit() {}
    virtual void show() = 0;
};

class Apple :public Fruit
{
public:
    Apple(){}
    virtual void show() override
    {
        std::cout << "我是一个苹果" << std::endl;
    }
};

class Banana :public Fruit
{
public:
    Banana(){}
    virtual void show() override
    {
        std::cout << "我是一个香蕉" << std::endl;
    }
};

class FruitFactory
{
public:
    virtual std::shared_ptr<Fruit> create() = 0;
};

class AppleFactory :public FruitFactory
{
public:
    virtual std::shared_ptr<Fruit> create()
    {
        return std::make_shared<Apple>();
    }
};

class BananaFactory :public FruitFactory
{
public:
    virtual std::shared_ptr<Fruit> create()
    {
        return std::make_shared<Banana>();
    }
};

int main()
{
    std::shared_ptr<FruitFactory> factory(new AppleFactory);
    std::shared_ptr<Fruit> fruit = factory->create();
    fruit->show();

    factory.reset(new BananaFactory());
    fruit = factory->create();
    fruit->show();
    return 0;
}